package com.system.honour.common;

import com.system.honour.beans.PageQuery;
import com.system.honour.exception.CustomizeErrorCode;
import com.system.honour.exception.CustomizeException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;


/**
* @Description:    封装返回信息
* @Author:         Joe
* @CreateDate:     2019/9/13 12:44
*/
@Data
public class ResultDTO<T> {
    @ApiModelProperty(value = "状态码")
    private Integer code;
    @ApiModelProperty(value = "消息说明")
    private String message;
    @ApiModelProperty(value = "数据量")
    private Integer count;
    @ApiModelProperty(value = "数据")
    private T data;
    @ApiModelProperty(value = "分页信息")
    private PageQuery pageQuery;


    public static ResultDTO errorOfLogin(){
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(800);
        resultDTO.setMessage("尚未登录，请登录");
        return resultDTO;
    }

    public static ResultDTO errorOf(Integer code,String message){
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(code);
        resultDTO.setMessage(message);
        return resultDTO;
    }

    public static ResultDTO errorOf(CustomizeErrorCode errorCode) {
        return errorOf(errorCode.getCode(),errorCode.getMessage());
    }

    public static ResultDTO errorOf(CustomizeException e){
        return errorOf(e.getCode(),e.getMessage());
    }

    public static ResultDTO okOf(){
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(200);
        resultDTO.setMessage("请求成功");
        return resultDTO;
    }
    public static <T> ResultDTO okOf( Integer count, T t, PageQuery pageQuery){
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(200);
        resultDTO.setMessage("请求成功");
        resultDTO.setCount(count);
        resultDTO.setData(t);
        resultDTO.setPageQuery(pageQuery);
        return resultDTO;
    }

    public static <T> ResultDTO okOf(T t){
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(200);
        resultDTO.setMessage("请求成功");
        resultDTO.setData(t);
        return resultDTO;
    }
}
